load("//bazel:macros.bzl", "exports_files_legacy", "select_multi", "selects", "skia_cc_deps", "skia_cc_library", "skia_objc_library")
load("//bazel:copts.bzl", "DEFAULT_OBJC_COPTS")

licenses(["notice"])

exports_files_legacy()

selects.config_setting_group(
    name = "dawn_unix",
    match_all = [
        "//src/gpu:dawn_backend",
        "@platforms//os:linux",
    ],
)

selects.config_setting_group(
    name = "gl_unix",
    match_all = [
        "//src/gpu:gl_backend",
        "@platforms//os:linux",
    ],
)

selects.config_setting_group(
    name = "gl_mac",
    match_all = [
        "//src/gpu:gl_backend",
        "@platforms//os:macos",
    ],
)

selects.config_setting_group(
    name = "vulkan_unix",
    match_all = [
        "//src/gpu:vulkan_backend",
        "@platforms//os:linux",
    ],
)

skia_cc_library(
    name = "sk_app",
    testonly = True,
    srcs = [
        "Window.cpp",
        "WindowContext.cpp",
        "RasterWindowContext.h",
    ] + select_multi(
        {
            "//src/gpu:dawn_backend": [
                "DawnWindowContext.h",
                "DawnWindowContext.cpp",
            ],
            "//src/gpu:gl_backend": [
                "GLWindowContext.cpp",
                "GLWindowContext.h",
            ],
            "//src/gpu:vulkan_backend": [
                "VulkanWindowContext.h",
                "VulkanWindowContext.cpp",
            ],
        },
    ) + select({
        "@platforms//os:linux": ["//tools/sk_app/unix:srcs"],
        "//conditions:default": [],
        # TODO(kjlubick) add Windows/Mac support
    }),
    hdrs = [
        "Application.h",
        "DisplayParams.h",
        "Window.h",
        "WindowContext.h",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        "//:skia_internal",
        "//tools/skui",
        "//tools/timer",
    ] + select({
        "@platforms//os:linux": ["//tools/sk_app/unix:deps"],
        "//conditions:default": [],
    }),
)

skia_objc_library(
    name = "sk_app_objc",
    testonly = True,
    srcs = [
        "Window.cpp",
        "WindowContext.cpp",
        "RasterWindowContext.h",
    ] + select_multi(
        {
            "//src/gpu:gl_backend": [
                "GLWindowContext.cpp",
                "GLWindowContext.h",
            ],
            #TODO dawn and metal backend
        },
    ) + select({
        "@platforms//os:macos": ["//tools/sk_app/mac:srcs"],
        "//conditions:default": [],
        # TODO ios support
    }),
    hdrs = [
        "Application.h",
        "DisplayParams.h",
        "Window.h",
        "WindowContext.h",
    ],
    copts = DEFAULT_OBJC_COPTS + [
        "-Wno-deprecated-declarations",
        "-DGL_SILENCE_DEPRECATION",
    ],
    sdk_frameworks = [
        "QuartzCore",
        "Cocoa",
        "Foundation",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":platform_deps",
        "//:skia_internal",
        "//tools/skui",
        "//tools/timer",
    ],
)

skia_cc_deps(
    name = "platform_deps",
    testonly = True,
    visibility = ["//visibility:private"],
    deps = select({
        "@platforms//os:macos": ["//tools/sk_app/mac:deps"],
        "//conditions:default": [],
    }),
)
